package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.CustomerDao;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: lei
 * @Date 2021/11/25 20:08
 **/
@Service
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    private CustomerDao customerDao;

    // 客户列表查询
    @Override
    public Map<String, Object> list(String page, String rows, String customerName) {
        List<Customer> list = customerDao.list(Integer.parseInt(page), Integer.parseInt(rows), customerName);
        Map map = new HashMap();
        map.put("total",list.size());
        map.put("rows",list);
        return map;
    }

    // 添加或修改用户
    @Override
    public void saveOrUpdate(Customer customer) {
        if (customer.getCustomerId()!=null){
            customerDao.update(customer);
        }else{
            customerDao.insert(customer);
        }
    }

    // 批量删除
    @Override
    public void delete(String ids) {
        String[] idArr = ids.split(",");
        customerDao.delete(idArr);
    }
}
